{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-10T07:38:30.658865Z",
     "start_time": "2025-10-10T07:38:30.654369Z"
    }
   },
   "source": [
    "# class Document():\n",
    "#     def __init__(self,title,author,context):\n",
    "#         self.title = title\n",
    "#         self.author = author\n",
    "#         self._context = context\n",
    "#     def get_context_length(self):\n",
    "#         return len(self._context)\n",
    "#     def intercept_context(self, length):\n",
    "#         self._context = self._context[:length]\n",
    "# harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...')\n",
    "#\n",
    "# print(harry_potter_book.title)\n",
    "# print(harry_potter_book.author)\n",
    "# print(harry_potter_book.get_context_length())\n",
    "# class Document():\n",
    "#\n",
    "#     WELCOME_STR = 'Welcome! The context for this book is {}.'\n",
    "#\n",
    "#     def __init__(self, title, author, context):\n",
    "#         print('init function called')\n",
    "#         self.title = title\n",
    "#         self.author = author\n",
    "#         self.__context = context\n",
    "#\n",
    "#     # 类函数\n",
    "#     @classmethod\n",
    "#     def create_empty_book(cls, title, author):\n",
    "#         return cls(title=title, author=author, context='nothing')\n",
    "#\n",
    "#     # 成员函数\n",
    "#     def get_context_length(self):\n",
    "#         return len(self.__context)\n",
    "#\n",
    "#     # 静态函数\n",
    "#     @staticmethod\n",
    "#     def get_welcome(context):\n",
    "#         return Document.WELCOME_STR.format(context)\n",
    "#\n",
    "#\n",
    "# empty_book = Document.create_empty_book('What Every Man Thinks About Apart from Sex', 'Professor Sheridan Simove')\n",
    "#\n",
    "#\n",
    "# print(empty_book.get_context_length())\n",
    "# print(empty_book.get_welcome('indeed nothing'))\n",
    "# class Entity():\n",
    "#     def __init__(self, object_type):\n",
    "#         # print('parent class init called')\n",
    "#         self.object_type = object_type\n",
    "#\n",
    "#     def get_context_length(self):\n",
    "#         raise Exception('get_context_length not implemented')\n",
    "#\n",
    "#     def print_title(self):\n",
    "#         print(self.title)\n",
    "#\n",
    "# class Document(Entity):\n",
    "#     def __init__(self, title, author, context):\n",
    "#         # print('Document class init called')\n",
    "#         Entity.__init__(self, 'document')\n",
    "#         self.title = title\n",
    "#         self.author = author\n",
    "#         self.__context = context\n",
    "#\n",
    "#     def get_context_length(self):\n",
    "#         return len(self.__context)\n",
    "#\n",
    "# class Video(Entity):\n",
    "#     def __init__(self, title, author, video_length):\n",
    "#         # print('Video class init called')\n",
    "#         Entity.__init__(self, 'video')\n",
    "#         self.title = title\n",
    "#         self.author = author\n",
    "#         self.__video_length = video_length\n",
    "#\n",
    "#     def get_context_length(self):\n",
    "#         return self.__video_length\n",
    "#\n",
    "# harry_potter_book = Document('Harry Potter(Book)', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...')\n",
    "# harry_potter_movie = Video('Harry Potter(Movie)', 'J. K. Rowling', 120)\n",
    "#\n",
    "# # print(harry_potter_book.object_type)\n",
    "# # print(harry_potter_movie.object_type)\n",
    "#\n",
    "# harry_potter_book.print_title()\n",
    "# harry_potter_movie.print_title()\n",
    "#\n",
    "# print(harry_potter_book.get_context_length())\n",
    "# print(harry_potter_movie.get_context_length())\n",
    "from abc import ABCMeta, abstractmethod\n",
    "\n",
    "class Entity(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def get_title(self):\n",
    "        pass\n",
    "\n",
    "    @abstractmethod\n",
    "    def set_title(self, title):\n",
    "        pass\n",
    "\n",
    "class Document(Entity):\n",
    "    def get_title(self):\n",
    "        return self.title\n",
    "\n",
    "    def set_title(self, title):\n",
    "        self.title = title\n",
    "\n",
    "document = Document()\n",
    "document.set_title('Harry Potter')\n",
    "print(document.get_title())\n",
    "\n",
    "entity = Document()"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Harry Potter\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "588e6f34ac39f961"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
